﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using Gizmox.WebGUI.Forms;
using Premiere.Window;

namespace PremiereMX
{
    public class TreeViewForm
    {
        public TreeViewForm Parent = null;
        public string ID = string.Empty;
        public string Text = string.Empty;
        public Hashtable Items = new Hashtable();
        UserControl m_userControl;

        public TreeViewForm(TreeViewForm parent, string id, string text)
        {
            Parent = parent;
            ID = id;
            Text = text;
        }
        private TreeViewForm(string id, string text)
        {
            ID = id;
            Text = text;
        }
        public TreeViewForm AddItem(string id, string text)
        {
            TreeViewForm item = new TreeViewForm(id, text);
            item.Parent = this;
            Items.Add(id, item);
            return item;
        }
        public void CreateFunctionMasterReport()
        {
            this.AddItem("Function", "Function");
            this.AddItem("Report", "Report");
        }
        public TreeViewForm GetItem(string name)
        {
            return (TreeViewForm)Items[name];
        }   
    }
    public class TreeViewFormFactory
    {
        public TreeViewForm MASTER = null;
        public TreeViewForm UTILITY = null;
        public TreeViewForm PROCESS = null;
        public TreeViewForm MASTERING = null;
        public TreeViewForm INVENTORY = null;
        public TreeViewForm PURCHASE = null;
        public TreeViewForm SALES = null;
        IMainForm m_mainForm = null;
        public const string PROFILE_SETUP_FORM = "ProfileSetupForm";
        public const string USER_SETUP_FORM = "UserForm";
        public const string RULES_SETUP_FORM = "RulesForm";
        public const string YEAR_FORM = "YearForm";
        public const string CURRENCY_FORM = "CurrencyForm";
        public const string DIVISION_FORM = "DivisionForm";
        private Hashtable m_userControlHashtable = new Hashtable();

        public TreeViewFormFactory(IMainForm mainForm)
        {
            m_mainForm = mainForm;
            MASTER = new TreeViewForm(null, "Master", "Master");
            UTILITY = MASTER.AddItem("Utility", "UTILITY");
            PROCESS = MASTER.AddItem("Process", "PROCESS");
            MASTERING = MASTER.AddItem("Mastering", "MASTER");
            INVENTORY = MASTER.AddItem("Inventory", "INVENTORY");
            PURCHASE = MASTER.AddItem("Purchase", "PURCHASE");
            SALES = MASTER.AddItem("Sales", "SALES");

            //UTILITY.AddItem("Profile", "Profile").CreateFunctionMasterReport();
            //UTILITY.AddItem("User", "User").CreateFunctionMasterReport();
            //UTILITY.AddItem("Rules", "Rules").CreateFunctionMasterReport();
            //UTILITY.AddItem("Year", "Year").CreateFunctionMasterReport();

            TreeViewForm generalMenu = MASTERING.AddItem("GeneralMenu", "General Menu");
            TreeViewForm distributionMenu = MASTERING.AddItem("Distribution", "Distribution");
            TreeViewForm inventoryMenu = MASTERING.AddItem("Inventory", "Inventory");
            TreeViewForm financeMenu = MASTERING.AddItem("Finance", "Finance");
            

            TreeViewForm gix = MASTER.GetItem("Utility").AddItem(PROFILE_SETUP_FORM, "General Information");//
            m_userControlHashtable.Add(PROFILE_SETUP_FORM, getUserControlGeneralSetUp());
            TreeViewForm usersetup = MASTER.GetItem("Utility").AddItem(USER_SETUP_FORM, "User Setup");
            m_userControlHashtable.Add(USER_SETUP_FORM, getUserControlUser());
            TreeViewForm rulesetup = MASTER.GetItem("Utility").AddItem(RULES_SETUP_FORM, "Rules Setup");
            m_userControlHashtable.Add(RULES_SETUP_FORM, getRulesControlUser());
            TreeViewForm yearsetup = MASTER.GetItem("Utility").AddItem(YEAR_FORM, "Year Setup");
            m_userControlHashtable.Add(YEAR_FORM, getUserControlYear());


            TreeViewForm currencysetup = generalMenu.AddItem(CURRENCY_FORM, "Currency Setup");
            m_userControlHashtable.Add(CURRENCY_FORM, getUserControlCurrency());
            TreeViewForm divisionsetup = generalMenu.AddItem(DIVISION_FORM, "Division Setup");
            m_userControlHashtable.Add(DIVISION_FORM, getUserControlDivision());
            TreeViewForm emplymastersetup = generalMenu.AddItem(FormFactory.EMPLOYEE_MASTER_FORM, "Employee Master Setup");
            m_userControlHashtable.Add(FormFactory.EMPLOYEE_MASTER_FORM, getUserControlEmployeeMaster());


            TreeViewForm customercategory = distributionMenu.AddItem(FormFactory.CUSTOMER_CATEGORY_FORM, "Customer Category Setup");
            m_userControlHashtable.Add(FormFactory.CUSTOMER_CATEGORY_FORM, getUserControlCustomerCategory());
            TreeViewForm suppliercategory = distributionMenu.AddItem(FormFactory.SUPPLIER_CATEGORY_FORM, "Supplier Category Setup");
            m_userControlHashtable.Add(FormFactory.SUPPLIER_CATEGORY_FORM, getUserControlSupplierCategory());
            TreeViewForm topcategory = distributionMenu.AddItem(FormFactory.TOP_FORM, "Term Of Payment Setup");
            m_userControlHashtable.Add(FormFactory.TOP_FORM, getUserControlTOP());
            TreeViewForm pricecategorycategory = distributionMenu.AddItem(FormFactory.PRICE_CATEGORY_FORM, "Price Category Setup");
            m_userControlHashtable.Add(FormFactory.PRICE_CATEGORY_FORM, getUserControlPriceCategory());
            TreeViewForm tax = distributionMenu.AddItem(FormFactory.TAX_FORM, "Tax Setup");
            m_userControlHashtable.Add(FormFactory.TAX_FORM, getUserControlTax());
            TreeViewForm customer = distributionMenu.AddItem(FormFactory.CUSTOMER_FORM, "Customer Setup");
            m_userControlHashtable.Add(FormFactory.CUSTOMER_FORM, getUserControlCustomer());
            TreeViewForm supplier = distributionMenu.AddItem(FormFactory.SUPPLIER_FORM, "Supplier Setup");
            m_userControlHashtable.Add(FormFactory.SUPPLIER_FORM, getUserControlSupplier());

            TreeViewForm unit = inventoryMenu.AddItem(FormFactory.UNIT_FORM, "Unit Setup");
            m_userControlHashtable.Add(FormFactory.UNIT_FORM, getUserControlUnit());
            TreeViewForm partcategory = inventoryMenu.AddItem(FormFactory.PART_CATEGORY_FORM, "Part Category Setup");
            m_userControlHashtable.Add(FormFactory.PART_CATEGORY_FORM, getUserControlPartCategory());
            TreeViewForm partgroup = inventoryMenu.AddItem(FormFactory.PART_GROUP_FORM, "Part Group Setup");
            m_userControlHashtable.Add(FormFactory.PART_GROUP_FORM, getUserControlPartGroup());
            TreeViewForm warehouse = inventoryMenu.AddItem(FormFactory.WAREHOUSE_FORM, "Warehouse Setup");
            m_userControlHashtable.Add(FormFactory.WAREHOUSE_FORM, getUserControlWarehouse());
            TreeViewForm part = inventoryMenu.AddItem(FormFactory.PART_FORM, "Part Setup");
            m_userControlHashtable.Add(FormFactory.PART_FORM, getUserControlPart());

            TreeViewForm documenttype = financeMenu.AddItem(FormFactory.DOCUMENT_TYPE_FORM, "Document Type Setup");
            m_userControlHashtable.Add(FormFactory.DOCUMENT_TYPE_FORM, getUserControlDocumentType());
            TreeViewForm bank = financeMenu.AddItem(FormFactory.BANK_FORM, "Bank Setup");
            m_userControlHashtable.Add(FormFactory.BANK_FORM, getUserControlBank());
            TreeViewForm exchangeRate = financeMenu.AddItem(FormFactory.EXCHANGE_RATE_FORM, "Exchange Rate Setup");
            m_userControlHashtable.Add(FormFactory.EXCHANGE_RATE_FORM, getUserControlExchangeRate());


           // TreeViewForm gi = UTILITY.GetItem("Profile").GetItem("Function").AddItem(PROFILE_SETUP_FORM, "General Information");//
           // m_userControlHashtable.Add(PROFILE_SETUP_FORM, getUserControlGeneralSetUp());
            //TreeViewForm usersetup = UTILITY.GetItem("User").GetItem("Function").AddItem(USER_SETUP_FORM, "User Setup");
            //m_userControlHashtable.Add(USER_SETUP_FORM, getUserControlUser());
            //TreeViewForm rulesetup = UTILITY.GetItem("Rules").GetItem("Function").AddItem(RULES_SETUP_FORM, "Rules Setup");
            //m_userControlHashtable.Add(RULES_SETUP_FORM, getRulesControlUser());
            //TreeViewForm yearsetup = UTILITY.GetItem("Year").GetItem("Function").AddItem(YEAR_FORM, "Year Setup");
            //m_userControlHashtable.Add(YEAR_FORM, getUserControlYear());

            //InitAllUserControl();

            TreeViewForm openingstock = MASTER.GetItem("Inventory").AddItem(FormFactory.OPENING_STOCK_FORM, "Opening Stock");
            m_userControlHashtable.Add(FormFactory.OPENING_STOCK_FORM, getUserControlOpeningStock());
        }

        private void InitAllUserControl()
        {
            foreach (string k in m_userControlHashtable.Keys)
            {
                UserControl uc = (UserControl)m_userControlHashtable[k];
                IUserControlBase ucb = (IUserControlBase)uc;
                if (ucb != null)
                    ucb.Init();
            }
        }

       
        public UserControl GetUserControlByID(string id)
        {
            return (UserControl)m_userControlHashtable[id];
        }
        private UserControlGeneralSetUp getUserControlGeneralSetUp()
        {
            return new UserControlGeneralSetUp(PROFILE_SETUP_FORM, m_mainForm);
        }
        private UserControlUser getUserControlUser()
        {
            return new UserControlUser(USER_SETUP_FORM, m_mainForm);
        }
        private UserControlRuleSetup getRulesControlUser()
        {
            return new UserControlRuleSetup(RULES_SETUP_FORM, m_mainForm);
        }
        private UserControlYear getUserControlYear()
        {
            return new UserControlYear(YEAR_FORM, m_mainForm);
        }
        private UserControlCurrency getUserControlCurrency()
        {
            return new UserControlCurrency(CURRENCY_FORM, m_mainForm);
        }
        private UserControlDivision getUserControlDivision()
        {
            return new UserControlDivision(DIVISION_FORM, m_mainForm);
        }
        private UserControlEmployeeMaster getUserControlEmployeeMaster()
        {
            return new UserControlEmployeeMaster(FormFactory.EMPLOYEE_MASTER_FORM, m_mainForm);
        }
        private UserControlCustomerCategory getUserControlCustomerCategory()
        {
            return new UserControlCustomerCategory(FormFactory.CUSTOMER_CATEGORY_FORM, m_mainForm);
        }
        private UserControlSupplierCategory getUserControlSupplierCategory()
        {
            return new UserControlSupplierCategory(FormFactory.SUPPLIER_CATEGORY_FORM, m_mainForm);
        }
        private UserControlTOP getUserControlTOP()
        {
            return new UserControlTOP(FormFactory.TOP_FORM, m_mainForm);
        }
        private UserControlPriceCategory getUserControlPriceCategory()
        {
            return new UserControlPriceCategory(FormFactory.PRICE_CATEGORY_FORM, m_mainForm);
        }
        private UserControlTax getUserControlTax()
        {
            return new UserControlTax(FormFactory.TAX_FORM, m_mainForm);
        }
        private UserControlCustomer getUserControlCustomer()
        {
            return new UserControlCustomer(FormFactory.CUSTOMER_FORM, m_mainForm);
        }
        private UserControlSupplier getUserControlSupplier()
        {
            return new UserControlSupplier(FormFactory.SUPPLIER_FORM, m_mainForm);
        }
        private UserControlUnit getUserControlUnit()
        {
            return new UserControlUnit(FormFactory.UNIT_FORM, m_mainForm);
        }
        private UserControlPartCategory getUserControlPartCategory()
        {
            return new UserControlPartCategory(FormFactory.PART_CATEGORY_FORM , m_mainForm);
        }
        private UserControlPartGroup getUserControlPartGroup()
        {
            return new UserControlPartGroup(FormFactory.PART_GROUP_FORM, m_mainForm);
        }
        private UserControlWarehouse getUserControlWarehouse()
        {
            return new UserControlWarehouse(FormFactory.WAREHOUSE_FORM, m_mainForm);
        }
        private UserControlPart getUserControlPart()
        {
            return new UserControlPart(FormFactory.PART_FORM, m_mainForm);
        }

        private UserControlDocumentType getUserControlDocumentType()
        {
            return new UserControlDocumentType(FormFactory.DOCUMENT_TYPE_FORM, m_mainForm);
        }
        private UserControlBank getUserControlBank()
        {
            return new UserControlBank(FormFactory.BANK_FORM, m_mainForm);
        }
        private UserControlExchangeRate getUserControlExchangeRate()
        {
            return new UserControlExchangeRate(FormFactory.EXCHANGE_RATE_FORM, m_mainForm);
        }
        private UserControlOpeningStock getUserControlOpeningStock()
        {
            return new UserControlOpeningStock(FormFactory.OPENING_STOCK_FORM, m_mainForm);
        }
    }
}
